hysop.core.arrays.array module

class hysop.core.arrays.array.Array(handle, backend, **kwds)[source]

Bases: object

Interface of an abstract array. An array is a numpy.ndarray work-alike that stores its data and performs its computations on various devices, depending on the backend. All exposed functions should work exactly as in numpy. Arithmetic methods in Array, when available, should at least support the broadcasting of scalars.

For Fortran users, reverse the usual order of indices when accessing elements of an array. to be in line with Python semantics and the natural order of the data. The fact is that Python indexing on lists and other sequences naturally leads to an outside-to inside ordering (the first index gets the largest grouping, and the last gets the smallest element).

See https://docs.scipy.org/doc/numpy-1.10.0/reference/internals.html for more information about C versus Fortran ordering in numpy.

Numpy notation are used for axes, axe 0 is the slowest varying index and last axe is the fastest varying index. By default:

3D C-ordering is [0,1,2] which corresponds to ZYX transposition state. 3D Fortran-ordering is [2,1,0] which corresponds to XYZ transposition state.

The last axe is the memory contiguous one (X in C-ordering and Z in Fortran-ordering). This means that when taking array byte strides, in the axis order, the strides are decreasing until the last stride wich is the size of array dtype in bytes.

Build an Array instance.

Parameters:
  • handle (buffer backend implementation)

  • backend (backend used to build this andle)

  • kwds (arguments for base classes.)

Notes

This should never be called directly by the user. Arrays should be constructed using array backend facilities, like zeros or empty. The parameters given here refer to a low-level method for instantiating an array.

property T

Same as self.transpose(), except that self is returned if self.ndim < 2.

__complex__()[source]

Return scalar value as a complex.

__int__()[source]

Return scalar value as an int.

__nonzero__()[source]

Called to implement truth value testing and the built-in operation bool().

all(axis=None, out=None, **kargs)[source]

Returns True if all elements evaluate to True.

any(axis=None, out=None, **kargs)[source]

Returns True if any of the elements of a evaluate to True.

argmax(axis=None, out=None, **kargs)[source]

Return indices of the maximum values along the given axis.

argmin(axis=None, out=None, **kargs)[source]

Return indices of the minimum values along the given axis of a.

argpartition(kth, axis=-1, kind='quicksort', order=None, **kargs)[source]

Returns the indices that would partition this array.

argsort(axis=-1, kind='quicksort', order=None, **kargs)[source]

Returns the indices that would sort this array.

abstract as_symbolic_array(name, **kwds)[source]

Return a symbolic array variable that contain a reference to this array.

abstract as_symbolic_buffer(name, **kwds)[source]

Return a symbolic buffer variable that contain a reference to this array.

astype(dtype, order=SAME_ORDER(3), casting='unsafe', subok=True, copy=True, **kargs)[source]

Copy of the array, cast to a specified type.

property backend

Return the backend corresponding to this array.

abstract property base

Base object if memory is from some other object.

byteswap(inplace=False, **kargs)[source]

Swap the bytes of the array elements Toggle between low-endian and big-endian data representation by returning a byteswapped array, optionally swapped in-place.

choose(choices, out=None, mode='raise', **kargs)[source]

Use an index array to construct a new array from a set of choices.

clip(min=None, max=None, out=None, **kargs)[source]

Return an array whose values are limited to min, max.

compress(condition, axis=None, out=None, **kargs)[source]

Return selected slices of this array along given axis.

conj(out=None, **kargs)[source]

Complex-conjugate of all elements.

conjugate(out=None, **kargs)[source]

Return the complex conjugate, element-wise.

copy(order=SAME_ORDER(3), **kargs)[source]

Return a copy of the array.

copy_from(src, **kargs)[source]

Copy data from buffer src

copy_to(dst, **kargs)[source]

Copy data from buffer to dst

ctype()[source]

Equivalent C type corresponding to the numpy.dtype.

property ctypes

An object to simplify the interaction of the array with the ctypes module.

cumprod(axis=None, dtype=None, out=None, **kargs)[source]

Return the cumulative product of the elements along the given axis.

cumsum(axis=None, dtype=None, out=None, **kargs)[source]

Return the cumulative sum of the elements along the given axis.

abstract property data

Buffer object pointing to the start of the array’s data

diagonal(offset=0, axis1=0, axis2=1, **kargs)[source]

Return specified diagonals.

dot(b, out=None, **kargs)[source]

Dot product of two arrays.

abstract property dtype

numpy.dtype representing the type stored into this buffer.

dump(file, **kargs)[source]

Dump a pickle of the array to the specified file.

dumps(**kargs)[source]

Returns the pickle of the array as a string.

fill(value, **kargs)[source]

Fill the array with a scalar value.

property flags

Information about the memory layout of the array.

flatten(order=SAME_ORDER(3), **kargs)[source]

Return a copy of the array collapsed into one dimension.

abstract get(handle=False)[source]

Returns a HostArray, view or copy of this array in the host memory. Usefull for backends thats do not share physical memory with the host.

get_T()[source]

Same as self.transpose(), except that self is returned if self.ndim < 2.

get_backend()[source]

Return the backend corresponding to this array.

abstract get_base()[source]

Base object if memory is from some other object.

get_ctypes()[source]

An object to simplify the interaction of the array with the ctypes module.

abstract get_data()[source]

Buffer object pointing to the start of the array’s data

get_data_base()[source]

For a given HostArray, finds the base array that ‘owns’ the actual data.

abstract get_dtype()[source]

numpy.dtype representing the type stored into this buffer.

get_flags()[source]

Information about the memory layout of the array.

get_handle()[source]

Return underlying implementation of this buffer.

get_imag()[source]

The imaginary part of the array.

abstract get_int_ptr()[source]

Return the underlying buffer pointer as an int.

get_itemsize()[source]

Number of bytes per element.

get_nbytes()[source]

Number of bytes in the whole buffer.

abstract get_ndim()[source]

Number of array dimensions.

abstract get_offset()[source]

Offset of array data in buffer.

get_order()[source]

Memory ordering. Determine whether the array view is written in C-contiguous order (last index varies the fastest), or FORTRAN-contiguous order in memory (first index varies the fastest). If dimension is one, default_order is returned.

get_real()[source]

The real part of the array.

abstract get_shape()[source]

The real shape of this buffer.

get_size()[source]

Number of elements in the array.

abstract get_strides()[source]

Tuple of ints that represents the byte step in each dimension when traversing an array.

getfield(dtype, offset=0)[source]

Returns a field of the given array as a certain type.

property handle

Return underlying implementation of this buffer.

property imag

The imaginary part of the array.

abstract property int_ptr

Return the underlying buffer pointer as an int.

is_c_contiguous()[source]

Return true if dimension is one or if current order is C_CONTIGUOUS.

is_fortran_contiguous()[source]

Return true if dimension is one or if current order is F_CONTIGUOUS.

is_fp()[source]

Return true if dtype is a floatting point type.

is_hysop_contiguous()[source]

Return true if dimension is one or if current order corresponds to hysop default order.

item(*args)[source]

Copy an element of an array to a standard Python scalar and return it.

itemset(*args)[source]

Insert scalar into an array (scalar is cast to array’s dtype, if possible)

property itemsize

Number of bytes per element.

logical_axes()[source]

Logical axes state ids, in numpy convention, as a tuple. Axe 0 is the slowest varying index, last axe is the fastest varying index. ie 3D C-ordering is [2,1,0]

3D fortran-ordering is [0,1,2]

Thoses are the axes seen as a numpy view on memory, only strides are permutated for access, Those axes are found by reverse argsorting the array strides, using a stable sorting algorithm.

Logical permutations can be achieved through numpy-like routines present in ArrayBackend:

*np.transpose *np.rollaxis *np.moveaxis *np.swapaxes

and Array property:

*Array.T

See Array.physical_axes() for physical permutations of axes. See Array.axes() for overall array permutation. See https://docs.scipy.org/doc/numpy-1.10.0/reference/internals.html for more information about C versus Fortran ordering in numpy.

max(axis=None, out=None, **kargs)[source]

Return the maximum along a given axis.

mean(axis=None, dtype=None, out=None, **kargs)[source]

Returns the average of the array elements along given axis.

min(axis=None, out=None, **kargs)[source]

Return the minimum along a given axis.

property nbytes

Number of bytes in the whole buffer.

abstract property ndim

Number of array dimensions.

nonzero(**kargs)[source]

Return the indices of the elements that are non-zero.

abstract property offset

Offset of array data in buffer.

property order

Memory ordering. Determine whether the array view is written in C-contiguous order (last index varies the fastest), or FORTRAN-contiguous order in memory (first index varies the fastest). If dimension is one, default_order is returned.

partition(kth, axis=-1, kind='quicksort', order=None, **kargs)[source]

Rearranges the elements in the array in such a way that value of the element i in kth position is in the position it would be in a sorted array.

prod(axis=None, dtype=None, out=None, **kargs)[source]

Return the product of the array elements over the given axis

ptp(axis=None, out=None, **kargs)[source]

Peak to peak (maximum - minimum) value along a given axis.

put(indices, values, mode='raise', **kargs)[source]

Set a.flatn = valuesn for all n in indices.

ravel(order=SAME_ORDER(3), **kargs)[source]

Return a flattened array.

property real

The real part of the array.

repeat(repeats, axis=None, **kargs)[source]

Repeat elements of an array.

reshape(new_shape, order=C_CONTIGUOUS(0), **kargs)[source]

Returns an array containing the same data with a new shape.

resize(new_shape, refcheck=True, **kargs)[source]

Change shape and size of array in-place.

round(decimals=0, out=None, **kargs)[source]

Return a with each element rounded to the given number of decimals.

searchsorted(v, side='left', sorter=None, **kargs)[source]

Find indices where elements of v should be inserted in a to maintain order.

abstract set_shape()[source]

Set the shape of this buffer. From the numpy doc: It is not always possible to change the shape of an array without copying the data. If you want an error to be raised if the data is copied, you should assign the new shape to the shape attribute of the array.

setfield(val, dtype, offset=0)[source]

Put a value into a specified place in a field defined by a data-type. Place val into a’s field defined by dtype and beginning offset bytes into the field.

setflags(write=None, align=None, uic=None)[source]

Set array flags WRITEABLE, ALIGNED, and UPDATEIFCOPY, respectively.

abstract property shape

The real shape of this buffer.

share_data(other)[source]

Returns true if self may share the same physical memory as other.

property size

Number of elements in the array.

sort(axis=-1, kind='quicksort', order=None, **kargs)[source]

Sort an array, in-place.

squeeze(axis=None, **kargs)[source]

Remove single-dimensional entries from the shape of a.

std(axis=None, dtype=None, out=None, ddof=0, **kargs)[source]

Returns the standard deviation of the array elements along given axis.

abstract property strides

Tuple of ints that represents the byte step in each dimension when traversing an array.

sum(axis=None, dtype=None, out=None, **kargs)[source]

Return the sum of the array elements over the given axis.

swapaxes(axis1, axis2, **kargs)[source]

Return a view of the array with axis1 and axis2 interchanged.

take(indices, axis=None, out=None, mode='raise', **kargs)[source]

Return an array formed from the elements of a at the given indices.

tobytes(order=C_CONTIGUOUS(0))[source]

Construct Python bytes containing the raw data bytes in the array.

tofile(fid, sep='', format='%s', **kargs)[source]

Write array to a file as text or binary (default). This is a convenience function for quick storage of array data. Information on endianness and precision is lost.

tolist(**kargs)[source]

Return the array as a possibly nested list.

tostring(order=SAME_ORDER(3), **kargs)[source]

Construct Python bytes containing the raw data bytes in the array.

trace(offset=0, axis1=0, axis2=1, dtype=None, out=None, **kargs)[source]

Return the sum along diagonals of the array.

transpose(axes=None, **kargs)[source]

Returns a view of the array with axes transposed.

transpose_to_state(state, **kargs)[source]

Transpose buffer to specified transposition state.

var(axis=None, dtype=None, out=None, ddof=0, **kargs)[source]

Returns the variance of the array elements, along given axis.

view(dtype=None, **kargs)[source]

New view of array with the same data.

wrap(handle)[source]

Wrap handle with the same initialization arguments as this instance.